package com.dianjing.dianjing.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dianjing.dianjing.dto.input.PaintingPageInput;
import com.dianjing.dianjing.dto.input.UserCollectionInput;
import com.dianjing.dianjing.dto.input.UserInput;
import com.dianjing.dianjing.dto.input.WorksInput;
import com.dianjing.dianjing.dto.output.PaintingOutput;
import com.dianjing.dianjing.dto.output.WorksDetailOutput;
import com.dianjing.dianjing.entity.Painting;
import com.dianjing.dianjing.enums.CollectionTypeEnum;
import com.dianjing.dianjing.service.PaintingService;
import com.dianjing.dianjing.service.UserCollectionService;
import com.dianjing.dianjing.util.DataUtils;
import com.dianjing.dianjing.util.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  作品
 * </p>
 *
 * @author owf
 * @since 2022-11-11
 */
@RestController
@RequestMapping("/painting")
@Api(tags = "作品模块")
public class PaintingController {

    @Resource
    private PaintingService paintingService;

    @Resource
    private UserCollectionService userCollectionService;

    @PostMapping("/show")
    @ApiOperation("作品展示列表")
    public IPage<Painting> show(@RequestBody @Valid PaintingPageInput input) {
        return paintingService.show(input);
    }

    @GetMapping("/detail")
    @ApiOperation("作品详情")
    public PaintingOutput detail(Long paintingId) {
        return paintingService.detail(paintingId);
    }

    @PostMapping("/collection")
    @ApiOperation("收藏作品")
    public ResponseData collect(@RequestBody @Valid UserCollectionInput input) {
        return userCollectionService.collect(input, CollectionTypeEnum.TYPE_PAINTING.getType());
    }

    @PostMapping("/worksUpload")
    @ApiOperation("作品上传")
    public DataUtils worksUpload(WorksInput worksInput) throws FileNotFoundException {

        Boolean isUploadSuccess = paintingService.worksUpload(worksInput);
        if(isUploadSuccess) {
            return DataUtils.ok();
        }else {
            return DataUtils.error("上传作品失败");
        }
    }
    @GetMapping("/seeMyWorks/{painterId}")
    @ApiOperation("查看我的作品")
    public DataUtils seeMyWorks(@PathVariable("painterId") Long painterId) {

        List<Painting> paintings = paintingService.seeMyWorks(painterId);
        if(paintings != null) {
            return DataUtils.ok(paintings);
        }else {
            return DataUtils.error("获取作品失败");
        }
    }
    @GetMapping("/seeWorks")
    @ApiOperation("查看指定类型下的作品")
    public DataUtils seeWorks(@RequestParam(value = "typeId",required = false) Long typeId) {

        List<Painting> paintings = paintingService.seeWorks(typeId);
        if(paintings != null) {
            return DataUtils.ok(paintings);
        }else {
            return DataUtils.error("获取作品失败");
        }
    }

    @GetMapping("/worksDetails/{worksId}")
    @ApiOperation("作品详情-更详情")
    public DataUtils worksDetails(@PathVariable("worksId") Long worksId) {
        WorksDetailOutput worksDetailOutput = paintingService.worksDetails(worksId);
        if (worksDetailOutput != null) {
            return DataUtils.ok(worksDetailOutput);
        }else  {
            return DataUtils.error("获取作品详情信息失败");
        }
    }

    @GetMapping("/seePainterWorks")
    @ApiOperation("获取指定画师，指定类型的作品")
    public DataUtils seeWorks(@RequestParam("painterId") Long painterId,
                              @RequestParam(value = "typeId",required = false) Long typeId) {
        List<Painting> paintings = paintingService.seeWorks(painterId,typeId);
        if (paintings != null) {
            return DataUtils.ok(paintings);
        }else  {
            return DataUtils.error("获取作品失败");
        }
    }




}

